#include<iostream>
#include<cstdio>
using namespace std;
int aa[10005],bb[10005],sum=0,n,m;
void ma_swap(int i,int j)
{
	int t;
	t=aa[j];aa[j]=aa[i];aa[i]=t;
}
void mb_swap(int i,int j)
{
	int t;
	t=bb[j];bb[j]=bb[i];bb[i]=t;
}
void m_qsort(int le,int ri)
{
	int i=le,j=ri,mid1=bb[(le+ri)/2],mid2=aa[(le+ri)/2];
	while (i<=j)
	{
		while (bb[i]<mid1||((bb[i]==mid1)&&(aa[i]<mid2))) i++;
		while (bb[j]>mid1||((bb[j]==mid1)&&(aa[j]>mid2))) j--;
		if (i<=j)
		{
			ma_swap(i,j);
			mb_swap(i,j);
			i++;j--;
		}
	}
	if (le<j) m_qsort(le,j);
	if (i<ri) m_qsort(i,ri);
}
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
		cin>>aa[i]>>bb[i];
	m_qsort(1,n);
	for(int i=1,x=-1;i<=n;i++){
		if (x>=aa[i]){
			continue;
		}
		sum++;
		x=bb[i];
	}
	printf("%d\n",sum);
	
	return 0;
}
